var __UISkill_instance = null;
function getUISkill() { return __UISkill_instance; }

var UISkill = function(){};

UISkill.prototype.onDidLoadFromCCB = function()
{
    cc.log("UISkill.onDidLoadFromCCB");
    __UISkill_instance = this;

    this._curSkill = -1;
};

// 发送设置主界面数据
UISkill.prototype.updateData = function()
{
    cc.log('UISkill.updateData');

    if(this._curSkill) {
        this.onSelectSkill(this._curSkill);
    }
}

// 选择技能
UISkill.prototype.onSelectSkill1 = function() { this.onSelectSkill(1); }
UISkill.prototype.onSelectSkill2 = function() { this.onSelectSkill(2); }
UISkill.prototype.onSelectSkill3 = function() { this.onSelectSkill(3); }
UISkill.prototype.onSelectSkill4 = function() { this.onSelectSkill(4); }
UISkill.prototype.onSelectSkill5 = function() { this.onSelectSkill(5); }
UISkill.prototype.onSelectSkill6 = function() { this.onSelectSkill(6); }

UISkill.prototype.onSelectSkill = function(skill) 
{
    cc.log('onSelectSkill '+skill);
    this._curSkill = skill;
    var lv = DataManager.playerSkillData[skill];
    if(!lv) {
        lv = 0;
    }
    this.setSkillDesc(skill, lv);
}

UISkill.prototype.setSkillDesc = function(skill, lv)
{
    this.txtCurLv.setString('当前等级:'+lv);
    this.txtCurDesc.setString('当前等级描述');
    this.txtCost.setString('消耗');
    this.txtNextDesc.setString('下个等级');
}

UISkill.prototype.onLevelUp = function() 
{
    if(this._curSkill == -1) return;
    
    function _func (data) {
        if(data['result']=='ok') {
            // 刷新数据
            DataManager.setData(data['data'])
            // 刷新界面
            getUISkill().updateData();
        }
    };
    gnet.sendHttp("skill_level_up", [this._curSkill], _func);
}




